package com.myzl.coal.client.channel.init;

import com.myzl.coal.client.BaseHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.handler.timeout.WriteTimeoutHandler;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


/**
 * @ClassName ClientChannelInitializer
 * @Author wzb
 * @Date 2023/1/18 16:08
 * @Description
 */
@Data
@AllArgsConstructor
@Component
@Slf4j
public class TestChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new IdleStateHandler(3, 5, 8));
        pipeline.addLast(new ReadTimeoutHandler(10));
        pipeline.addLast(new WriteTimeoutHandler(10));
        //异步执行
        pipeline.addLast(BaseHandler.group,new WriteTimeoutHandler(10));
//        NettyBootStrap.getHandler(deviceProtocol,pipeline);
//        IdleStateHandler idleStateHandler = new IdleStateHandler(0, 1, 2);
//        long lastReadTime = idleStateHandler.lastReadTime;
//        ctx
    }
}
